package com.yitao.cms.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class Swagger2Config {

    @Value("${swagger.is}")
    private Boolean bool = false;

    @Bean
    public Docket createRestApi() {
        if (bool == Boolean.FALSE) {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(new ApiInfoBuilder()
                            .title("")
                            .description("")
                            .license("")
                            .licenseUrl("")
                            .termsOfServiceUrl("")
                            .version("")
                            .contact(new Contact("", "", ""))
                            .build())
                    .select()
                    .paths(PathSelectors.none())//如果是线上环境，添加路径过滤，设置为全部都不符合
                    .build();
        } else {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(new ApiInfoBuilder()
                            .title("一桃")
                            .termsOfServiceUrl("http://www.yitao.com/")
                            .version("1.0.0")
                            .build())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.yitao.cms"))
                    .paths(PathSelectors.any())
                    .build();
        }
    }

}
